package com.zzyang.aop.demo.interceptor;

import com.zzyang.aop.demo.interceptor.anno.AopMarker;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @author zhuoziyang
 * @date 2021/5/16 23:31
 */
@Component
public class AopInterceptorBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean.getClass().isAnnotationPresent(AopMarker.class)) {
//            return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), bean.getClass().getInterfaces(), new AopInterceptorInvocationHandler(bean));
            return new CglibHandler(bean).createProxyObject();
        }
        return bean;
    }

}
